package com.xieh.webmagic.magic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.RedisScheduler;

/**
 * @author 谢辉
 * @Classname UserTask
 * @Description TODO
 * @Date 2020/11/20 16:44
 */
@Component
public class UserTask {

    @Autowired
    private UserProcessor userProcessor;

    @Autowired
    private UserPipeline userPipeline;

    @Autowired
    private RedisScheduler redisScheduler;

    // 表示每天的19:02:00执行
    @Scheduled(cron = "0 2 19 * * ?")
    public void UserTask(){
        System.out.println("开启了定时任务.....");
        Spider spider = Spider.create(userProcessor);
        spider.addUrl("https://blog.csdn.net/");
        spider.addPipeline(userPipeline);
        spider.setScheduler(redisScheduler);
        spider.start();
    }

}

